<template>
  <div class="wrapper">
    <div class="search">
      <div class="search_back iconfont" @click="handleBackClick"> &#xe6f2;</div>
      <div class="search_content">
        <span class="search_content_icon iconfont">&#xe62d;</span>
        <input class="search_content_input" placeholder="请输入商品名称">
      </div>
    </div>
    <ShopInfo :item="item" :hideBorder="true" v-show="item.imgUrl"/>
    <Content :shopName="item.name"/>
    <Cart/>
  </div>
</template>

<script>
import { reactive, toRefs } from 'vue'
import ShopInfo from '@/components/ShopInfo'
import Content from './Content'
import Cart from './Cart'
import { useRoute, useRouter } from 'vue-router'
import { get } from '@/utils/request'

const useShopInfoEffect = () => {
  const route = useRoute()
  const data = reactive({ item: {} })
  const getItemData = async () => {
    const result = await get(`api/shop/${route.params.id}`)
    if (result?.code === 2000) {
      data.item = result.data
    }
  }
  const { item } = toRefs(data)
  return {
    item,
    getItemData
  }
}
const useHandleBackClick = () => {
  const router = useRouter()
  const handleBackClick = () => {
    router.back()
  }
  return handleBackClick
}
export default {
  name: 'Shop',
  components: {
    Cart,
    ShopInfo,
    Content
  },

  setup () {
    const { item, getItemData } = useShopInfoEffect()
    getItemData()
    const handleBackClick = useHandleBackClick()
    return {
      item,
      handleBackClick
    }
  }
}
</script>

<style lang="scss" scoped>
@import '../../style/viriables.scss';

.wrapper {
  padding: 0 .18rem;
}

.search {
  height: .32rem;
  margin: .14rem 0 .04rem 0;
  display: flex;
  line-height: .32rem;

  &_back {
    height: .32rem;
    width: .3rem;
    font-size: .24rem;
    color: #B6B6B6;
  }

  &_content {
    display: flex;
    flex: 1;
    line-height: .32rem;
    border-radius: .16rem;
    background: $search-bgColor;

    &_icon {
      width: .44rem;
      text-align: center;
      color: $search-fontColor;
    }

    &_input {
      width: 100%;
      display: block;
      border: none;
      outline: none;
      background: none;
      padding-right: .2rem;
      height: .32rem;
      font-size: .14rem;
      color: $content-fontcolor;

      &::placeholder {
        color: $content-fontcolor;
      }
    }
  }
}

</style>
